Skip to content

Commit

Permalink
deserialize everything that sqs does
Browse files Browse the repository at this point in the history
  • Loading branch information
lucix-aws committed Jan 30, 2024
1 parent 4aefd70 commit 5bed7a9
Show file tree
Hide file tree
Showing 6 changed files with 441 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ public static final class Context {
public static final Symbol Context = SmithyGoDependency.CONTEXT.valueSymbol("Context");
}

public static final class Encoding {
public static final class Json {
public static final Symbol NewDecoder = SmithyGoDependency.JSON.valueSymbol("NewDecoder");
public static final Symbol Number = SmithyGoDependency.JSON.valueSymbol("Number");
}

public static final class Base64 {
public static final Symbol StdEncoding = SmithyGoDependency.BASE64.valueSymbol("StdEncoding");
}
}

public static final class Fmt {
public static final Symbol Errorf = SmithyGoDependency.FMT.valueSymbol("Errorf");
public static final Symbol Sprintf = SmithyGoDependency.FMT.valueSymbol("Sprintf");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ public static ChainWritable of(GoWriter.Writable... writables) {
return chain;
}

public static ChainWritable of(List<GoWriter.Writable> writables) {
public static ChainWritable of(Collection<GoWriter.Writable> writables) {
var chain = new ChainWritable();
chain.writables.addAll(writables);
return chain;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public static final class Smithy {
public static final class Ptr {
public static final Symbol String = SmithyGoDependency.SMITHY_PTR.valueSymbol("String");
public static final Symbol Bool = SmithyGoDependency.SMITHY_PTR.valueSymbol("Bool");
public static final Symbol Int8 = SmithyGoDependency.SMITHY_PTR.valueSymbol("Int8");
public static final Symbol Int16 = SmithyGoDependency.SMITHY_PTR.valueSymbol("Int16");
public static final Symbol Int32 = SmithyGoDependency.SMITHY_PTR.valueSymbol("Int32");
public static final Symbol Int64 = SmithyGoDependency.SMITHY_PTR.valueSymbol("Int64");
}

public static final class Middleware {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ public static boolean isUniverseType(Symbol symbol) {
.orElse(false);
}

public static boolean isPointable(Symbol symbol) {
return symbol.getProperty(SymbolUtils.POINTABLE, Boolean.class).orElse(false);
}

/**
* Builds a symbol within the context of the package in which codegen is taking place.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package software.amazon.smithy.go.codegen.service;

import static java.util.stream.Collectors.toSet;

import java.util.Set;
import java.util.stream.Stream;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.shapes.CollectionShape;
import software.amazon.smithy.model.shapes.MapShape;
import software.amazon.smithy.model.shapes.Shape;
import software.amazon.smithy.model.shapes.StructureShape;

public final class Util {
private Util() {}

public static Set<StructureShape> getShapesToSerde(Model model, StructureShape shape) {
return Stream.concat(
Stream.of(shape),
shape.members().stream()
.map(it -> targetOrSelf(model, model.expectShape(it.getTarget())))
.filter(Shape::isStructureShape)
.flatMap(it -> getShapesToSerde(model, (StructureShape) it).stream())
).collect(toSet());
}

private static Shape targetOrSelf(Model model, Shape shape) {
if (shape instanceof CollectionShape) {
return targetOrSelf(model, model.expectShape(((CollectionShape) shape).getMember().getTarget()));
} else if (shape instanceof MapShape) {
return targetOrSelf(model, model.expectShape(((MapShape) shape).getValue().getTarget()));
}
return shape;
}
}
Loading

0 comments on commit 5bed7a9

Please sign in to comment.