Debian Codegraph @

stacks/linkedliststack/serialization.go

raw symbols SCIP
1 // Copyright (c) 2015, Emir Pasic. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package linkedliststack
6
7 import (
8 "github.com/emirpasic/gods/v2/containers"
9 )
10
11 // Assert Serialization implementation
12 var _ containers.JSONSerializer = (*Stack[int])(nil)
13 var _ containers.JSONDeserializer = (*Stack[int])(nil)
14
15 // ToJSON outputs the JSON representation of the stack.
16 func (stack *Stack[T]) ToJSON() ([]byte, error) {
17 return stack.list.ToJSON()
18 }
19
20 // FromJSON populates the stack from the input JSON representation.
21 func (stack *Stack[T]) FromJSON(data []byte) error {
22 return stack.list.FromJSON(data)
23 }
24
25 // UnmarshalJSON @implements json.Unmarshaler
26 func (stack *Stack[T]) UnmarshalJSON(bytes []byte) error {
27 return stack.FromJSON(bytes)
28 }
29
30 // MarshalJSON @implements json.Marshaler
31 func (stack *Stack[T]) MarshalJSON() ([]byte, error) {
32 return stack.ToJSON()
33 }