podman
65 строк · 1.4 Кб
1// Copyright (C) MongoDB, Inc. 2017-present.
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may
4// not use this file except in compliance with the License. You may obtain
5// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6
7package bsoncodec8
9import "fmt"10
11type mode int12
13const (14_ mode = iota15mTopLevel
16mDocument
17mArray
18mValue
19mElement
20mCodeWithScope
21mSpacer
22)
23
24func (m mode) String() string {25var str string26
27switch m {28case mTopLevel:29str = "TopLevel"30case mDocument:31str = "DocumentMode"32case mArray:33str = "ArrayMode"34case mValue:35str = "ValueMode"36case mElement:37str = "ElementMode"38case mCodeWithScope:39str = "CodeWithScopeMode"40case mSpacer:41str = "CodeWithScopeSpacerFrame"42default:43str = "UnknownMode"44}45
46return str47}
48
49// TransitionError is an error returned when an invalid progressing a
50// ValueReader or ValueWriter state machine occurs.
51type TransitionError struct {52parent mode
53current mode
54destination mode
55}
56
57func (te TransitionError) Error() string {58if te.destination == mode(0) {59return fmt.Sprintf("invalid state transition: cannot read/write value while in %s", te.current)60}61if te.parent == mode(0) {62return fmt.Sprintf("invalid state transition: %s -> %s", te.current, te.destination)63}64return fmt.Sprintf("invalid state transition: %s -> %s; parent %s", te.current, te.destination, te.parent)65}
66