github.com/cloudwego/frugal@v0.1.15/internal/binary/encoder/opcode.go (about)

     1  /*
     2   * Copyright 2022 ByteDance Inc.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package encoder
    18  
    19  import (
    20      `fmt`
    21  )
    22  
    23  type OpCode uint8
    24  
    25  const (
    26      OP_size_check OpCode = iota
    27      OP_size_const
    28      OP_size_dyn
    29      OP_size_map
    30      OP_size_defer
    31      OP_byte
    32      OP_word
    33      OP_long
    34      OP_quad
    35      OP_sint
    36      OP_length
    37      OP_memcpy_be
    38      OP_seek
    39      OP_deref
    40      OP_defer
    41      OP_map_len
    42      OP_map_key
    43      OP_map_next
    44      OP_map_value
    45      OP_map_begin
    46      OP_map_if_next
    47      OP_map_if_empty
    48      OP_list_decr
    49      OP_list_begin
    50      OP_list_if_next
    51      OP_list_if_empty
    52      OP_unique
    53      OP_goto
    54      OP_if_nil
    55      OP_if_hasbuf
    56      OP_if_eq_imm
    57      OP_if_eq_str
    58      OP_make_state
    59      OP_drop_state
    60      OP_halt
    61  )
    62  
    63  var _OpNames = [256]string {
    64      OP_size_check    : "size_check",
    65      OP_size_const    : "size_const",
    66      OP_size_dyn      : "size_dyn",
    67      OP_size_map      : "size_map",
    68      OP_size_defer    : "size_defer",
    69      OP_byte          : "byte",
    70      OP_word          : "word",
    71      OP_long          : "long",
    72      OP_quad          : "quad",
    73      OP_sint          : "sint",
    74      OP_length        : "length",
    75      OP_memcpy_be     : "memcpy_be",
    76      OP_seek          : "seek",
    77      OP_deref         : "deref",
    78      OP_defer         : "defer",
    79      OP_map_len       : "map_len",
    80      OP_map_key       : "map_key",
    81      OP_map_next      : "map_next",
    82      OP_map_value     : "map_value",
    83      OP_map_begin     : "map_begin",
    84      OP_map_if_next   : "map_if_next",
    85      OP_map_if_empty  : "map_if_empty",
    86      OP_list_decr     : "list_decr",
    87      OP_list_begin    : "list_begin",
    88      OP_list_if_next  : "list_if_next",
    89      OP_list_if_empty : "list_if_empty",
    90      OP_unique        : "unique",
    91      OP_goto          : "goto",
    92      OP_if_nil        : "if_nil",
    93      OP_if_hasbuf     : "if_hasbuf",
    94      OP_if_eq_imm     : "if_eq_imm",
    95      OP_if_eq_str     : "if_eq_str",
    96      OP_make_state    : "make_state",
    97      OP_drop_state    : "drop_state",
    98      OP_halt          : "halt",
    99  }
   100  
   101  var _OpBranches = [256]bool {
   102      OP_map_if_next   : true,
   103      OP_map_if_empty  : true,
   104      OP_list_if_next  : true,
   105      OP_list_if_empty : true,
   106      OP_goto          : true,
   107      OP_if_nil        : true,
   108      OP_if_hasbuf     : true,
   109      OP_if_eq_imm     : true,
   110      OP_if_eq_str     : true,
   111  }
   112  
   113  func (self OpCode) String() string {
   114      if _OpNames[self] != "" {
   115          return _OpNames[self]
   116      } else {
   117          return fmt.Sprintf("OpCode(%d)", self)
   118      }
   119  }